﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElingOA6_DSJCJ.Models;
using System.Data;

namespace ElingOA6_DSJCJ.Common
{
    /// <summary>
    /// 视图中DataRow对象获取实体类
    /// </summary>
    public class ViewDataRowToModel
    {
        /// <summary>
        /// 获得文档对象列表(用于表格显示)
        /// </summary>
        public static List<DocumentGridModel> DataTableToListDocuemt(DataTable dt)
        {
            List<DocumentGridModel> modelList = new List<DocumentGridModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                DocumentGridModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModelDocument(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获得通讯录对象列表(用于表格显示)
        /// </summary>
        public static List<HREmplGrid> DataTableToListHREmpl(DataTable dt)
        {
            List<HREmplGrid> modelList = new List<HREmplGrid>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HREmplGrid model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModelHREmpl(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获得问卷主题数据列表(用于表格显示)
        /// </summary>
        public static List<ElingOA6_DSJCJ.Model.Paper> DataTableToListPaper(DataTable dt)
        {
            List<ElingOA6_DSJCJ.Model.Paper> modelList = new List<ElingOA6_DSJCJ.Model.Paper>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_DSJCJ.Model.Paper model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModelPaper(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        /// <summary>
        /// 得到一个文档对象实体(用于表格显示)
        /// </summary>
        private static DocumentGridModel DataRowToModelDocument(DataRow row)
        {
            DocumentGridModel model = new DocumentGridModel();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row.Table.Columns.Contains("FDocClsName"))
                {
                    if (row["FDocClsName"] != null)
                    {
                        model.FDocClsName = row["FDocClsName"].ToString();
                    }
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                if (row["FDisplayDate"] != null && row["FDisplayDate"].ToString() != "")
                {
                    model.FDisplayDate = DateTime.Parse(row["FDisplayDate"].ToString());
                }
                
                if (row["FTitle"] != null)
                {
                    model.FTitle = row["FTitle"].ToString();
                }
                if (row.Table.Columns.Contains("FIsTop"))
                {
                    if (row["FIsTop"] != null && row["FIsTop"].ToString() != "")
                    {
                        model.FIsTop = int.Parse(row["FIsTop"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FStatus"))
                {
                    if (row["FStatus"] != null)
                    {
                        model.FStatus = row["FStatus"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FIsEnroll"))
                {
                    if (row["FIsEnroll"] != null)
                    {
                        model.FIsEnroll = row["FIsEnroll"].ToString();
                    }
                }
                if (row["FEmpName"] != null)
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
                if (row["FDeptName"] != null)
                {
                    model.FDeptName = row["FDeptName"].ToString();
                }
                if (row.Table.Columns.Contains("FStatus"))
                {
                    if (row["FIsNeedAudit"] != null)
                    {
                        model.FIsNeedAudit = row["FIsNeedAudit"].ToString();
                    }
                }
                if (row["FWorkGrpName"] != null)
                {
                    model.FWorkGrpName = row["FWorkGrpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelEmpName"))
                {
                    model.FDelEmpName = row["FDelEmpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelEmpName"))
                {
                    model.FDelEmpName = row["FDelEmpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelDate"))
                {
                    if (row["FDelDate"] != null && row["FDelDate"].ToString() != "")
                    {
                        model.FDelDate = DateTime.Parse(row["FDelDate"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FEditMode"))
                {
                    if (row["FEditMode"] != null)
                    {
                        model.FEditMode = row["FEditMode"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FTopSeq"))
                {
                    if (row["FTopSeq"] != null && row["FTopSeq"].ToString() != "")
                    {
                        model.FTopSeq = int.Parse(row["FTopSeq"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FThumbSrvFileName"))
                {
                    if (row["FThumbSrvFileName"] != null && row["FThumbSrvFileName"].ToString()!="")
                    {
                        model.FThumbSrvFileName = row["FThumbSrvFileName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FContentTxt"))
                {
                    if (row["FContentTxt"] != null && row["FContentTxt"].ToString() != "")
                    {
                        model.FContentTxt = row["FContentTxt"].ToString();
                    }
                }
            }
            return model;
        }
        /// <summary>
        /// 得到一个文档对象实体(用于表格显示)
        /// </summary>
        private static HREmplGrid DataRowToModelHREmpl(DataRow row)
        {
            HREmplGrid model = new HREmplGrid();
            if (row != null)
            {
                if (row["FEmpName"] != null)
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
                if (row["FDutyName"] != null)
                {
                    model.FDutyName = row["FDutyName"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FDeptName"] != null)
                {
                    model.FDeptName = row["FDeptName"].ToString();
                }
                if (row["FOfficeTel"] != null)
                {
                    model.FOfficeTel = row["FOfficeTel"].ToString();
                }
                if (row["FEmpName"] != null)
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
                if (row["FJob"] != null)
                {
                    model.FJob = row["FJob"].ToString();
                }
                if (row["FMobile"] != null)
                {
                    model.FMobile = row["FMobile"].ToString();
                }
                if (row["FHomeTel"] != null)
                {
                    model.FHomeTel = row["FHomeTel"].ToString();
                }

            }
            return model;
        }
        /// <summary>
        /// 得到一个问卷对象实体(用于表格显示)
        /// <creator>wangl</creator>
        /// <date>2013-09-11</date>
        /// </summary>
        private static Model.Paper DataRowToModelPaper(DataRow row)
        {
            Model.Paper model = new Model.Paper();
            if (row != null)
            {
                if (row["FPaperClsNo"] != null)
                {
                    model.FPaperClsNo = row["FPaperClsNo"].ToString();
                }
                if (row["FTitle"] != null)
                {
                    model.FTitle = row["FTitle"].ToString();
                }
                if (row["FContent"] != null)
                {
                    model.FContent = row["FContent"].ToString();
                }
                if (row["FIsRecordName"] != null)
                {
                    model.FIsRecordName = row["FIsRecordName"].ToString();
                }
                if (row["FBeginDate"] != null && row["FBeginDate"].ToString() != "")
                {
                    model.FBeginDate = DateTime.Parse(row["FBeginDate"].ToString());
                }
                if (row["FEndDate"] != null && row["FEndDate"].ToString() != "")
                {
                    model.FEndDate = DateTime.Parse(row["FEndDate"].ToString());
                }
                if (row["FResultIsOpen"] != null)
                {
                    model.FResultIsOpen = row["FResultIsOpen"].ToString();
                }
                if (row["FPaperId"] != null && row["FPaperId"].ToString() != "")
                {
                    model.FPaperId = decimal.Parse(row["FPaperId"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                
                if (row["FPubDeptNo"] != null)
                {
                    model.FPubDeptNo = row["FPubDeptNo"].ToString();
                }
                if (row["FPubEmpNo"] != null)
                {
                    model.FPubEmpNo = row["FPubEmpNo"].ToString();
                }
                if (row["FPubIp"] != null)
                {
                    model.FPubIp = row["FPubIp"].ToString();
                }
                if (row["FPaperType"] != null)
                {
                    model.FPaperType = row["FPaperType"].ToString();
                }
                if (row["FIsVoteIPControl"] != null)
                {
                    model.FIsVoteIPControl = row["FIsVoteIPControl"].ToString();
                }
                if (row["FIsLookIPControl"] != null)
                {
                    model.FIsLookIPControl = row["FIsLookIPControl"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得文明台账对象列表(用于历史传真)
        /// </summary>
        public static List<AccManagerDocGridModel> DataTableToListACCDocuemt(DataTable dt)
        {
            List<AccManagerDocGridModel> modelList = new List<AccManagerDocGridModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                AccManagerDocGridModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModelACCDocument(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static AccManagerDocGridModel DataRowToModelACCDocument(DataRow row)
        {
            AccManagerDocGridModel model = new AccManagerDocGridModel();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = int.Parse(row["FDocId"].ToString());
                }
                if (row["FDirId"] != null && row["FDirId"].ToString() != "")
                {
                    model.FDirId = int.Parse(row["FDirId"].ToString());
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FFileName"] != null)
                {
                    model.FFileName = row["FFileName"].ToString();
                }
                if (row["FFileType"] != null)
                {
                    model.FFileType = row["FFileType"].ToString();
                }
                if (row["FFileUrl"] != null)
                {
                    model.FFileUrl = row["FFileUrl"].ToString();
                }
                if (row["FFilePath"] != null)
                {
                    model.FFilePath = row["FFilePath"].ToString();
                }
                if (row["FUpdateTime"] != null && row["FUpdateTime"].ToString() != "")
                {
                    model.FUpdateTime = DateTime.Parse(row["FUpdateTime"].ToString());
                }
                if (row["FDispSeq"] != null && row["FDispSeq"].ToString() != "")
                {
                    model.FDispSeq = int.Parse(row["FDispSeq"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FSize"] != null && row["FSize"].ToString() != "")
                {
                    model.FSize = long.Parse(row["FSize"].ToString());
                }
                if (row["FIsDelete"] != null && row["FIsDelete"].ToString() != "")
                {
                    model.FIsDelete = decimal.Parse(row["FIsDelete"].ToString());
                }
                if (row["FContentTxt"] != null)
                {
                    model.FContentTxt = row["FContentTxt"].ToString();
                }
                if (row["FContentBin"] != null && row["FContentBin"].ToString() != "")
                {
                    model.FContentBin = (byte[])row["FContentBin"];
                }
                if (row["FBGMusicPath"] != null)
                {
                    model.FBGMusicPath = row["FBGMusicPath"].ToString();
                }
                if (row["FResponsible"] != null)
                {
                    model.FResponsible = row["FResponsible"].ToString();
                }
                if (row["FIsDeptControl"] != null && row["FIsDeptControl"].ToString() != "")
                {
                    model.FIsDeptControl = int.Parse(row["FIsDeptControl"].ToString());
                }
                if (row["FPlayInterval"] != null && row["FPlayInterval"].ToString() != "")
                {
                    model.FPlayInterval = int.Parse(row["FPlayInterval"].ToString());
                }
                if (row["FCreateDate"] != null && row["FCreateDate"].ToString() != "")
                {
                    model.FCreateDate = DateTime.Parse(row["FCreateDate"].ToString());
                }
                if (row["FShowDate"] != null && row["FShowDate"].ToString() != "")
                {
                    model.FShowDate = DateTime.Parse(row["FShowDate"].ToString());
                }
                if (row["FFileNo"] != null)
                {
                    model.FFileNo = row["FFileNo"].ToString();
                }
                if (row["FFileNoDate"] != null && row["FFileNoDate"].ToString() != "")
                {
                    model.FFileNoDate = DateTime.Parse(row["FFileNoDate"].ToString());
                }
                if (row["FIsSecret"] != null)
                {
                    model.FIsSecret = row["FIsSecret"].ToString();
                }
                if (row.Table.Columns.Contains("FDeptName"))
                {
                    if (row["FDeptName"] != null)
                    {
                        model.FDeptName = row["FDeptName"].ToString();
                    }
                }
            }
            return model;
        }





    }
}
